package com.homer.gps.track.helper;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

public class DirectoryHelper {

	public DirectoryHelper() {
	}

	public static DirectoryHelper getInstance() {
		return new DirectoryHelper();
	}
	
	public static void deleteFile(String path) {
		File f = new File(path);
		if (f.exists())
			f.delete();
	}

	public static void deleteDirectory(String directoryPath) {
		new DeleteDirThread(directoryPath).start();
	}

	private static class DeleteDirThread extends Thread {

		private String directoryPath;

		public DeleteDirThread(String directoryPath) {
			this.directoryPath = directoryPath;
		}

		@Override
		public void run() {
			super.run();
			File f = new File(directoryPath);
			if (f.exists()) {
				try {
					FileUtils.cleanDirectory(f);
					FileUtils.deleteDirectory(f);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

	}

}
